package com.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dao.AdminsDao;
import com.dao.PinglunDao;
import com.entity.Admins;
import com.entity.Pinglun;
import com.util.SafeUtil;

/**
 * 评论服务
 */
@Service	// 注解为service层spring管理bean
@Transactional	// 注解此类所有方法加入spring事务, 具体设置默认
public class PinglunService {

	@Autowired
	private PinglunDao pinglunDao;
	
	


	/**
	 * 通过用户名获取
	 * @param username
	 * @return
	 */
	public List<Pinglun> getByGoodId(int goodId) {
		return pinglunDao.getByGoodId(goodId);
	}
	
	/**
	 * 列表
	 * @param page
	 * @param rows
	 * @return
	 */
	public List<Pinglun> getList(int page, int rows) {
		return pinglunDao.getList(rows * (page-1), rows);
	}

	/**
	 * 总数
	 * @return
	 */
	public long getTotal() {
		return pinglunDao.getTotal();
	}

	/**
	 * 通过id查询
	 * @param id
	 * @return
	 */
	public Pinglun get(int id) {
		return pinglunDao.selectById(id);
	}
	
	/**
	 * 添加
	 * @param admin
	 */
	public Integer add(Pinglun pinglun) {
		return pinglunDao.insert(pinglun);
	}
	
	

	/**
	 * 删除
	 * @param user
	 */
	public boolean delete(Pinglun pinglun) {
		return pinglunDao.deleteById(pinglun.getId()) > 0;
	}

	
}
